var app = angular.module('ZJPC');

app.controller('CheckController', ['$scope', 'CesiumService', function($scope, CesiumService) {

    $scope.persons = [
        {"id":1, "class":"monitor", "name":"监控", "content":"monitorBox", "state":false},
        {"id":2, "class":"face", "name":"人脸", "content":"faceBox", "state":false},
        {"id":3, "class":"bayonet", "name":"卡口", "content":"bayonetBox", "state":false},
        {"id":4, "class":"icard", "name":"刷卡", "content":"icardBox", "state":false},
        {"id":5, "class":"wifi", "name":"WIFI", "content":"wifiBox", "state":false}
    ];
    $scope.chose = -1;  
    $scope.changeAll = function(chose){
        $scope.chose = chose == 0 ? -1 : 0;
        if($scope.chose == 0){
            for(var i = 0; i < $scope.persons.length; i++){
                $scope.persons[i].state = true;
                setStatus(true);
            }
        }else{
             for(var i = 0; i < $scope.persons.length; i++){
                $scope.persons[i].state = false;
                setStatus(false);
            }
        }
    };
    
    $scope.selected = function($event, id){
        $scope.persons[id - 1].state = $scope.persons[id - 1].state == true ? false : true;
        var count = 0;
        for(var i = 0; i < $scope.persons.length; i++){
            if($scope.persons[i].state == true){
                CesiumService.setEntityStatus(CesiumService[$scope.persons[i].content], true);
                count++;
            }else{
                CesiumService.setEntityStatus(CesiumService[$scope.persons[i].content], false);
            }
        }
        if(count == $scope.persons.length){
            $scope.chose = 0;
            setStatus(true);
        }else{
            $scope.chose = -1;
        }

    };  

    function setStatus (status){
        CesiumService.setEntityStatus(CesiumService.monitorBox, status);
        CesiumService.setEntityStatus(CesiumService.faceBox, status);
        CesiumService.setEntityStatus(CesiumService.bayonetBox, status);
        CesiumService.setEntityStatus(CesiumService.icardBox, status);
        CesiumService.setEntityStatus(CesiumService.wifiBox, status);
    }

    $scope.custom = true;
    $scope.equiState = function (){
        $scope.custom = $scope.custom == false ? true : false;
    }

    $scope.equiHide = function (){
        $scope.custom = $scope.custom == false ? true : false;
    }


}])
